package com.marketingexpert.controller.marketingmgnt.autoMarketing;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.marketingexpert.exception.MarketingExpertException;
import com.marketingexpert.service.marketingmgnt.MarketingService;
import com.marketingexpert.util.Resources;

public class SaveTrendController implements Controller {

	private MarketingService marketingService;
	
	private String dispatchUrl;
	
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		request.setCharacterEncoding("UTF8");
		
		String[] trends = request.getParameterValues("channel_group");
		String[] weiboUserIds = request.getParameterValues("WeiboId");
		
		String parentUserID = (String) request.getSession().getAttribute("parentUserId");
		
		try {
			marketingService.saveAutoMarketingTrends(trends,weiboUserIds,parentUserID);
			request.setAttribute("succ", Resources.getString("SaveTrendController.saveAutoMarketingSuccess"));
			return new ModelAndView(dispatchUrl); 
		} catch(MarketingExpertException e) {
			request.setAttribute("failed",Resources.getString("SaveTrendController.saveAutoMarketingFailed"));
			return new ModelAndView(dispatchUrl); 
		}
	}

	public MarketingService getMarketingService() {
		return marketingService;
	}

	public void setMarketingService(MarketingService marketingService) {
		this.marketingService = marketingService;
	}

	public String getDispatchUrl() {
		return dispatchUrl;
	}

	public void setDispatchUrl(String dispatchUrl) {
		this.dispatchUrl = dispatchUrl;
	}
	
	

}
